package cn.iocoder.yudao.module.system.controller.admin.patentapplication.vo;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.ArrayList;
import java.time.LocalDate;
import java.time.LocalDateTime;
import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import cn.iocoder.yudao.framework.common.DictTypeConstants;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import cn.iocoder.yudao.framework.dict.core.DictFrameworkUtils;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import org.springframework.format.annotation.DateTimeFormat;

import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;

@Data
@Schema(description = "管理后台 - 会员专利申请 Response VO")
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper=true)
@ExcelIgnoreUnannotated
public class PatentApplicationNewRespVO extends TenantBaseDO {

    @ExcelProperty("id")
    @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "22877")
    private Long id;

    @ExcelProperty("创建时间")
    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
    private LocalDateTime createTime;

    @ExcelProperty("答复期限")
    @Schema(description = "答复期限")
    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY)
    @DateTimeFormat(pattern=FORMAT_YEAR_MONTH_DAY)
    private LocalDate responseDeadline;

    @ExcelProperty("案件id")
    @Schema(description = "案件id", example = "30321")
    private Long caseId;

    @ExcelProperty("上传日期")
    @Schema(description = "上传日期")
    @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY)
    @DateTimeFormat(pattern=FORMAT_YEAR_MONTH_DAY)
    private LocalDate uploadDate;

    @ExcelProperty("普通用户id")
    @Schema(description = "普通用户id", example = "2822")
    private Long userId;

    @ExcelProperty("其他文件")
    @Schema(description = "其他文件")
    private List<String>reviewMaterialsFiles=new ArrayList<>();

    @Schema(description = "返稿文件")
    @ExcelProperty("返稿文件")
    private List<String>returnFiles=new ArrayList<>();

    @ExcelProperty("案件名称")
    @Schema(description = "案件名称", example = "案件名称")
    private String caseName;

    @ExcelProperty("撰写人id")
    @Schema(description = "撰写人id", example = "")
    private Long reviewerBy;

    @ExcelProperty("撰写人")
    @Schema(description = "撰写人", example = "")
    private String reviewer;

    @ExcelProperty("企业名称")
    @Schema(description = "企业名称", example = "")
    private String enterprise;


    @ExcelProperty("是否上传返稿文件")
    @Schema(description = "是否上传返稿文件", example = "")
    private Boolean ifUpload;
    /**
     * 费用缴纳状态
     * payment_status
     * 1,已缴年费
     * 2,未缴年费
     * 3,已缴申请费
     * 4,未缴申请费
     */
    @DictFormat(DictTypeConstants.PAYMENT_STATUS)
    @Schema(description = "费用缴纳状态", example = "")
    private String paymentStatus;
    /**
     * 案件状态
     * case_status
     * 1,撰写中
     * 2,待提交
     * 3,待补充
     * 4,受理
     * 5,初审中
     * 6,实质审查中
     * 7,审查答复中
     * 8,补正中
     * 9,驳回
     * 10,代办登记
     * 11,授权
     * 12,未缴费过期
     * 13,恢复中
     * 14,转让中
     */
    @Schema(description = "案件状态", example = "")
    @DictFormat(DictTypeConstants.CASE_STATUS)
    private String caseStatus;
    @DictFormat(DictTypeConstants.CASE_TYPE)
    @Schema(description = "案件状态", example = "")
    private String caseType;
    @Schema(description = "更新时间", example = "")
    private String updateTimeStr;
    @ExcelProperty("是否上传返稿文件")
    @Schema(description = "是否逾期", example = "")
    private Boolean ifLate=false;

    public Boolean getIfUpload() {
        return !returnFiles.isEmpty();
    }


    public String getCaseType() {
        if (StrUtil.isBlank(caseType)){
            return "";
        }
        return DictFrameworkUtils.getDictDataLabel(DictTypeConstants.CASE_TYPE,caseType);
    }

    public String getPaymentStatus() {
        if (StrUtil.isBlank(paymentStatus)){
            return "";
        }
        return DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PAYMENT_STATUS,paymentStatus);
    }

    public String getCaseStatus() {
        if (StrUtil.isBlank(caseStatus)){
            return "";
        }
        return DictFrameworkUtils.getDictDataLabel(DictTypeConstants.CASE_STATUS,caseStatus);
    }

    public String getUpdateTimeStr() {
        LocalDateTime updateTime = super.getUpdateTime();
        if(ObjectUtil.isNull(updateTime)){
             return "";
         }
        return updateTime.format(DateTimeFormatter.ofPattern(FORMAT_YEAR_MONTH_DAY));
    }

    public Boolean getIfLate() {
        if(ObjectUtil.isNull(responseDeadline)){
            return false;
        }else{
            if(ObjectUtil.isNotNull(uploadDate)){
                return responseDeadline.isAfter(uploadDate);
            }else {
                return responseDeadline.isAfter(LocalDate.now());
            }
        }
    }


}